#include "AdminLogin.h"
#include "ui_AdminLogin.h"
#include "form.h"
#include "database.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_querys_clicked()
{
    Form *f=new Form();
    f->show();
}


void Widget::on_insert_clicked()
{
    QString isbn=ui->isbn->text();
    if(!isbn.isEmpty()){
        QString title=ui->title->text();
        QString name=ui->name->text();

        QString category=ui->category->text();
        DataBase da("root","lbhxksY12");
        da.libInsert(isbn,category,name,title);
    }else{
        QMessageBox::warning(this, "错误提示","isbn条码号不能为空");
    }

}


void Widget::on_deletes_clicked()
{
    QString isbn=ui->isbn->text();
    if(!isbn.isEmpty()){
        DataBase da("root","lbhxksY12");
        da.libDelete(isbn);
    }else{
        QMessageBox::warning(this, "错误提示","isbn条码号不能为空");
    }
}


void Widget::on_updates_clicked()
{
    QString isbn=ui->isbn->text();
    if(!isbn.isEmpty()){
        QString title=ui->title->text();
        QString name=ui->name->text();

        QString category=ui->category->text();
        DataBase da("root","lbhxksY12");
        da.libInsert(isbn,category,name,title);
    }else{
        QMessageBox::warning(this, "错误提示","isbn条码号不能为空");
    }
}


void Widget::on_overback_clicked()
{
    QDialog *inputDialog = new QDialog(this);
    inputDialog->setWindowTitle("逾期还书窗口");

    QGridLayout *layout = new QGridLayout(inputDialog);

    QLineEdit *lineEdit1 = new QLineEdit();
    QLineEdit *lineEdit2 = new QLineEdit();
    QPushButton *okButton = new QPushButton("OK");

    layout->addWidget(new QLabel("卡号:"), 0, 0);
    layout->addWidget(lineEdit1, 0, 1);
    layout->addWidget(new QLabel("书号:"), 1, 0);
    layout->addWidget(lineEdit2, 1, 1);
    layout->addWidget(okButton, 2, 1);

    connect(okButton, &QPushButton::clicked, inputDialog, [inputDialog, lineEdit1, lineEdit2]() {
        QString data1 = lineEdit1->text();
        QString data2 = lineEdit2->text();
        DataBase da("root","lbhxksY12");
        da.overDue(data1,data2);

        inputDialog->close();
    });

    inputDialog->exec();
}


void Widget::on_backup_clicked()
{
    DataBase da("root","lbhxksY12");
    da.dateBackups();
}


void Widget::on_doback_clicked()
{
    DataBase da("root","lbhxksY12");
    da.restoreDatabase();
}

